﻿Public Class ActivityDocument
    Inherits FitDocument

    Private mCurrentLap As Lap
    Private mCurrentSession As Session

    Public Sub New()
        mSessions = New List(Of Session)
        mCurrentSession = New Session
        mCurrentLap = New Lap
    End Sub

    Private mActivityType As ActivityEnum
    Public ReadOnly Property ActivityType As ActivityEnum
        Get
            Return mActivityType
        End Get
    End Property

    Private mSessions As List(Of Session)
    Public ReadOnly Property Sessions As List(Of Session)
        Get
            Return mSessions
        End Get
    End Property

    Private mActivityMessage As ActivityMessage
    Public ReadOnly Property ActivityMessage As ActivityMessage
        Get
            Return mActivityMessage
        End Get
    End Property


    Protected Overrides Sub ProcessMessage(message As MessageBase)
        If TypeOf message Is ActivityMessage Then
            mActivityMessage = CType(message, FitLib.ActivityMessage)
        ElseIf TypeOf message Is SessionMessage Then
            mCurrentSession.SessionMessage = CType(message, SessionMessage)
            mSessions.Add(mCurrentSession)
            mCurrentSession = New Session
            'mCurrentLap = New Lap
        ElseIf TypeOf message Is LapMessage Then
            mCurrentLap.LapMessage = CType(message, LapMessage)
            mCurrentSession.Laps.Add(mCurrentLap)
            mCurrentLap = New Lap
        ElseIf TypeOf message Is RecordMessage Then
            mCurrentLap.AddRecord(CType(message, RecordMessage))
        End If
    End Sub

End Class
